import pandas as pd
from dbtool import MysqlPool
import pymysql
from sqlalchemy import create_engine
db = MysqlPool()

df = pd.read_csv("shang_zheng_var_v1.csv")
df.round(3)
data = []

for index, row in df.iterrows():
    stock = row['symbol'][-2:].lower() + row['symbol'][0:6]
    data.append('("%s", "%s", %s, %s)' % (stock, row['day'], round(row["close_var_f"], 3), round(row["close_f"], 3)))
    print(row['symbol'], row['day'], row["close_var_f"], row["close_f"])
    if len(data) >= 50:
        sql = "insert into quan (symbol, tday, var_f, close_f) values " + ",".join(data)
        print(sql)
        count = db.execute(sql, ())
        print("count", count)
        db.commit()
        data = []
db.close()
